home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Technotools
/
Technotools (Chestnut CD-ROM)(1993).ISO
/
lang_oth
/
mawk10
/
fpe_test.v7
< prev
next >
Wrap
Text File
|
1991-10-05
|
2KB
|
87 lines
: tests if mawk has been compiled to correctly handle
: floating point exceptions
test1='BEGIN{ print 4/0 }'
test2='BEGIN {
x = 100
do { y = x ; x *= 1000 } while ( y != x )
print "loop terminated"
}'
test3='BEGIN{ print log(-8) }'
echo "testing division by zero"
echo mawk "$test1"
./mawk "$test1"
ret1=$?
echo
echo "testing overflow"
echo mawk "$test2"
./mawk "$test2"
ret2=$?
echo
echo "testing domain error"
echo mawk "$test3"
./mawk "$test3" > temp$$
ret3=$?
cat temp$$
echo
: the returns should all be zero or all 1
: core dumps not allowed
echo
echo ==============================
echo return1 = $ret1
echo return2 = $ret2
echo return3 = $ret3
[ $ret1 -gt 128 ] && { echo test1 failed ; exception=1 ; }
[ $ret2 -gt 128 ] && { echo test2 failed ; exception=1 ; }
[ $ret3 -gt 128 ] && { echo test3 failed ; exception=1 ; }
[ "$exception" = 1 ] && { rm -f core temp$$ ; exit 1 ; }
same=0
[ $ret1 = $ret2 ] && [ $ret2 = $ret3 ] && same=1
if [ $same = 1 ]
then
if [ $ret1 = 0 ]
then
echo results consistent: ignoring floating exceptions
if grep -i nan temp$$ > /dev/null
then :
else
echo "but the library is not IEEE754 compatible"
echo "test 3 failed"
rm temp$$
fi
else echo results consistent: trapping floating exceptions
fi
rm -f temp$$
exit 0
else
echo results are not consistent
echo 'return values should all be 0 if ignoring FPEs (i.e. with IEEE754)
or all 1 if trapping FPEs
'
rm -f temp$$
exit 1
fi